import cv2
import matplotlib.pyplot as plt
import numpy as np

img = cv2.imread('img/example.png')

blue = img[:, :, 0: 1]
green = img[:, :, 1: 2]
red = img[:, :, 2: 3]

black = np.zeros(shape=blue.shape, dtype=img.dtype)

blue_img =np.concatenate((blue, black, black), axis=2)
green_img =np.concatenate((black, green, black), axis=2)
red_img =np.concatenate((black, black, red), axis=2)

plt.subplot(1, 3, 1)
# BGR颜色模式转为RGB
plt.imshow(cv2.cvtColor(blue_img, cv2.COLOR_BGR2RGB))

plt.subplot(1, 3, 2)
plt.imshow(cv2.cvtColor(green_img, cv2.COLOR_BGR2RGB))

plt.subplot(1, 3, 3)
plt.imshow(cv2.cvtColor(red_img, cv2.COLOR_BGR2RGB))

plt.axis('off')
plt.show()
